package com.woniuxy.patrol.controller;

import com.woniuxy.patrol.pojo.PatrolPlan;
import com.woniuxy.patrol.service.PatrolPlanService;
import com.woniuxy.common.utils.ResponseUtil;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import java.util.List;

/**
 * 巡更计划控制器（对应《巡更demo.docx》3.5节巡更计划与任务功能）
 */
@RestController
@RequestMapping("/patrol/plan")
public class PatrolPlanController {

    @Resource
    private PatrolPlanService planService;

    /**
     * 按社区查询巡更计划（对应《巡更demo.docx》中巡更计划列表的社区筛选功能）
     */
    @GetMapping("/list")
    public ResponseUtil getByCommunity(@RequestParam Long communityId) {
        return planService.getByCommunityId(communityId);
    }

    /**
     * 添加巡更计划（对应《巡更demo.docx》6.27.1添加巡更计划功能）
     */
    @PostMapping("/add")
    public ResponseUtil addPlan(@RequestBody PlanWithRoutes planWithRoutes) {
        return planService.addPlan(planWithRoutes.getPlan(), planWithRoutes.getRouteIds());
    }

    /**
     * 编辑巡更计划
     */
    @PostMapping("/update")
    public ResponseUtil updatePlan(@RequestBody PlanWithRoutes planWithRoutes) {
        return planService.updatePlan(planWithRoutes.getPlan(), planWithRoutes.getRouteIds());
    }

    /**
     * 删除巡更计划（对应《巡更demo.docx》中计划列表的删除功能）
     */
    @GetMapping("/delete")
    public ResponseUtil deletePlan(@RequestParam Long planId) {
        return planService.deletePlan(planId);
    }

    /**
     * 内部静态类：用于接收计划与关联的路线ID列表
     */
    public static class PlanWithRoutes {
        private PatrolPlan plan;
        private List<Long> routeIds;

        // getter和setter
        public PatrolPlan getPlan() { return plan; }
        public void setPlan(PatrolPlan plan) { this.plan = plan; }
        public List<Long> getRouteIds() { return routeIds; }
        public void setRouteIds(List<Long> routeIds) { this.routeIds = routeIds; }
    }
}